<!--
 * @description  :案件列表
 * @descriptionDetail:案件列表
 * @copyright    : 浙江烟草
 * @author       : dw
 * @create       : 2022-10-20 18:35:52
-->
<template>
  <view class="page" style="margin: 0px -52rpx">
    <u-gap :height="$theme.cm_section_top_gap_height" :bg-color="$theme.cm_gap_color"></u-gap>
    <view class="nolicence-search-lay">
      <u-search
        class="nolicence-search"
        shape="round"
        :clearabled="true"
        :showAction="true"
        actionText="确定"
        :animation="true"
        placeholder="案件编号"
        v-model="searchKey"
        @custom="toSearchList"
      ></u-search>
    </view>
    <mescroll-list
      :i="0"
      :index="0"
      height="350px"
      :load-data="loadData"
      ref="mescrollItem0"
    >
      <template #default="d">
        <view class="card">
          <u-row @tap="handlerSelectItem(d.data)">
            <u-col span="11">
              <case-list-item :itemInfo="d.data"></case-list-item>
            </u-col>
            <u-col span="1" style="text-align:right;">
              <u-icon
                name="checkbox-mark"
                color="#2979ff"
                size="38"
                style="margin-right: 10px;"
                v-if="selectedUids.includes(d.data.caseUuid)"
              ></u-icon>
            </u-col>
          </u-row>
        </view>
      </template>
    </mescroll-list>
  </view>
</template>

<script>
import mescrollList from '@/components/mescroll_list.vue';
import MescrollMoreMixin from "@/components/mescroll-uni/mixins/mescroll-more.js";
import caseListItem from './caseListItem.vue';
import storeService from '@/service/store/store.service.js';
export default {
  components: {
    // MeTable,
    caseListItem,
    mescrollList,
  },
  mixins: [MescrollMoreMixin,],
  data() {
    return {
      selectedUids: [],     // 选中项的ids
      selectedItems: [],     // 选中项
      objInfo:{},
      defaultOrg:undefined,
      type:undefined,
      searchKey:"",
    };
  },
  methods: {
    // 选中
    handlerSelectItem(data) {
      let selectItems = this.selectedItems.filter(item => { return item.caseUuid == data.caseUuid })
      if(selectItems.length > 0){
        this.selectedItems = this.selectedItems.filter(s => s.caseUuid != data.caseUuid);
        this.selectedUids = this.selectedUids.filter(i => i != data.caseUuid);
      } else {
        this.selectedItems.push(data);
        this.selectedUids.push(data.caseUuid);
      }
      this.$emit('selectList',this.selectedUids);
    },
    toSearchList(){
      this.getMescroll(0).triggerDownScroll();
    },
    // 在线案件查询数据
    loadData(page) {
      let params = {
        page:page.num,
        limit:page.size,
        paras:{
          caseCode:this.searchKey,
        },
      }
      return new Promise((resolve,reject) => {
        storeService.getCaseByStore(params,'all').then(res => {
          if(res.success){
            resolve({
              count: res.count,
              data:res.data,
            });
          }else{
            this.$u.toast(res.msg);
            resolve({
              count: 0,
              data:[],
            });
          }
        }).catch(e => {
          this.$u.toast('请求失败:' + e);
          resolve({
            count: 0,
            data:[],
          });
        });
      })
    },
  },
};
</script>

<style lang="scss" scoped>
@import "@/style/common/rightMenu.scss";
.page{
  padding: 0;
}
.card{
  margin: 22rpx 42rpx;
}
.nolicence-search-lay {
  background-color: #fff;
  width: 100%;
  overflow: hidden;
  padding: 0 32rpx;
}
.nolicence-search {
  padding: 10px;
}
.u-page{
  padding-bottom: 100rpx;
}
</style>
